﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GtsServer.DAL;
using GtsServer.Model;
using Pub.Class;

namespace GtsServer.Charge.CallBack
{
    public class ZhiFuBaoCallBack
    {
        OrderDAL orderDAL = new OrderDAL();
        GtsServer.DAL.PrizeTaskReocrd prizetaskreocrdDAL = new DAL.PrizeTaskReocrd();
        public string json = string.Empty;

        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            json = Request2.GetRequestInputStream().UrlDecode();
            string orderID = GetTypeName("out_trade_no").ToStr();

            int status = GetTypeName("trade_status") == "TRADE_FINISHED" ? Convert.ToInt32(OrderStutas.成功) : Convert.ToInt32(OrderStutas.不成功);

            if (!string.IsNullOrEmpty(orderID))
                orderDAL.UpdateOrderStutas(orderID, status);

        }

        public string GetTypeName(string type)
        {
            return (json.GetMatchingValues("<" + type + ">(.+?)</" + type + ">", "<" + type + ">", "</" + type + ">").FirstOrDefault() ?? "").Trim();
        }

    }
}
